put RenameFile((filePath & stackName),"tempStack") into errmsg
OsErr(errmsg)
put RenameFile((filePath & revertName),stackName) into errmsg
OsErr(errmsg)
put DeleteFile((filePath & "tempStack")) into errmsg
OsErr(errmsg)
put empty into revertName
put "0" into ItemChosen
go to origCard
end if
put empty into ItemChosen
End openCard
--
on OsErr err
-- Translate the most common ones
if err = 0 then exit OsErr
if err > 0 then -- XFCN convention
put "Parameter error with function" into errstr
else if err is -59 then
put "Problem during rename" into errstr
else if err is -54 then
put "Attempt to open locked file for writing" into errstr
else if err is -46 then
put "Volume locked by software" into errstr
else if err is -45 then
put "File locked" into errstr
else if err is -44 then
put "Volume locked by hardware" into errstr
else if err is -43 then
put "File not found" into errstr
else if err is -37 then
put "Bad volume or file name" into errstr
else if err is -36 then
put "I/O error" into errstr
else if err is -35 then
put "No such volume" into errstr
else if err is -34 then
put "Disk is full" into errstr
else if err is -49 then
put "File already open for writing" into errstr
else
put "Failed with error" && err into errstr
end if
answer errstr with "OK"
end OsErr
-- part 6 (button)
-- low flags: 00
-- high flags: 8006
-- rect: left=18 top=296 right=316 bottom=87
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Saved
----- HyperTalk script -----
on mousedown
global ItemChosen
if the optionkey is down then
edit script of target
exit mousedown
end if
put the mouseloc into myPlace
put item 1 of myPlace - 20 into horiz
put item 2 of myPlace - 10 into vert
get PopUpMenu ("Save ;Revert ", 0, vert, horiz)
put it into ItemChosen
end mousedown
on mouseUp
global stackName,revertName,filePath,stacks
global ItemChosen,origCard
if ItemChosen is 1 then
put (short name of this stack) into stackName
put GetPath(stackName,stacks) into filePath
put "Copy of " & stackName into revertName
put DeleteFile((filePath & revertName)) into errmsg
if errmsg is -43 then
put 0 into errmsg
end if
OsErr(errmsg)
set hilite of target to false
doMenu Save a Copy...
set hilite of target to true
end if
if ItemChosen is 2 then
set hilite of target to false
if revertName is empty or stackName is "Revert Stack" then
answer "Sorry, Unable to Revert"
else
put long name of this card into origCard
go to card "Revert Card" of stack "Revert Stack"
end if
end if
end mouseUp
--
function GetPath name,pathlist
repeat with i = 1 to the number of lines in pathlist
if line i of pathlist is empty then next repeat -- sanity check
put line i of pathlist & name into fname
if FileModDate(fname,true) is not empty then -- found it
return line i of pathlist
end if
end repeat
return empty -- file not found in pathlist
end GetPath
on OsErr err
-- Translate the most common ones
if err = 0 then exit OsErr
if err > 0 then -- XFCN convention
put "Parameter error with function" into errstr
else if err is -59 then
put "Problem during rename" into errstr
else if err is -54 then
put "Attempt to open locked file for writing" into errstr
else if err is -46 then
put "Volume locked by software" into errstr
else if err is -45 then
put "File locked" into errstr
else if err is -44 then
put "Volume locked by hardware" into errstr
else if err is -43 then
put "File not found" into errstr
else if err is -37 then
put "Bad volume or file name" into errstr
else if err is -36 then
put "I/O error" into errstr
else if err is -35 then
put "No such volume" into errstr
else if err is -34 then
put "Disk is full" into errstr
else if err is -49 then
put "File already open for writing" into errstr
else
put "Failed with error" && err into errstr
end if
answer errstr with "OK"
end OsErr
-- part 7 (button)
-- low flags: 00
-- high flags: 0000
-- rect: left=459 top=298 right=322 bottom=489
-- title width / last selected line: 0
-- icon id / first selected line: 19678 / 19678
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Info
----- HyperTalk script -----
on mouseUp
show card field "Info"
end mouseUp
-- part 8 (field)
-- low flags: 81
-- high flags: 2007
-- rect: left=122 top=59 right=294 bottom=369
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: Info
----- HyperTalk script -----
on mouseUp
hide card field "Info"
end mouseUp
-- part contents for background part 3
----- text -----
9:44 PM
-- part contents for background part 2
----- text -----
Tuesday, January 5, 1988
-- part contents for background part 1
----- text -----
Card:
-- part contents for background part 5
----- text -----
1
-- part contents for background part 43
----- text -----
1
-- part contents for background part 45
----- text -----
Total Cards:
-- part contents for background part 42
----- text -----
Scripting
-- part contents for card part 8
----- text -----
Revert Stack 1.0
Call me old-fashioned, but I miss the security of the good old Revert menu option when I'm tweaking scripts in the stack I'm working on. Sure, there's lots of ways to back up a stack, but inventing one more was a good excuse to try out HyperTalk.
Revert will make a duplicate copy of the stack from which it is invoked, then rename and open the backup copy when requested, trashing any changes made to the original.
Click anywhere on this text to put it away.
How to install:
Using the button tool, select and copy the
"Saved" button in the lower left hand corner of this card.
Open the stack you want to install Revert in and paste in the button. Drag it anywhere you want.
You will also need to install the PopUpMenu,FileModDate, and DeleteFile XFCNs in your stack if they are not already there. Copies of these XFCNs may be found in Revert. The Developer Stack by Steve Drazga also contains these and other useful things (including a resource installer) and is available on GEnie.
How to save:
Click and hold over the radio button or the word "Saved" until the pop-up menu appears.Select the "Save" item.
When the "Save a Copy" dialog box appears, click the "Save" button. Do not alter the name that appears in the dialog box edit field.
Once the operation is completed,the "Saved" radio button will be highlighted to indicate that the stack has been backed up.
How to revert:
Click and hold over the radio button or the word "Saved" until the pop-up menu appears.Select the "Revert" item.
When the operation is completed,the "Saved" radio button will be empty to indicate that the stack has been restored to the saved copy.
Credits:
The XFCNs used in this stack were obtained from the Developer Stack uploaded to GEnie by Steve Drazga (S.DRAZGA). Other contributors are credited there. Syntax and HyperTalk usage were cribbed from the HyperStation stack also by Steve Drazga. (Thanks Steve!)
Disclaimer:
I've tried to cover all the obvious things that could occur during execution of Revert. Nevertheless, be cautious when using it. I'd like to hear about anything you notice during its use.
Request for ideas, suggestions:
This is my first effort using HyperTalk and I know that there are many improvements which can be made. If anyone has any suggestions or wishes to point out other HyperTalk methods that I could use, they would be very gratefully received.